﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
//using PowerCreator.LMS.Logic.Common;

namespace PowerCreator.LMS.Web
{
    public partial class SetManagerCourse : PowerCreator.LMS.Web.Base.BasePage
    {
        //PowerCreator.LMS.Logic.ActionManager.ManagerResource managerResourceManager = new PowerCreator.LMS.Logic.ActionManager.ManagerResource();
        //PowerCreator.LMS.Logic.CourseManager.ManagerCourseInfo courseManager = new PowerCreator.LMS.Logic.CourseManager.ManagerCourseInfo();
        //PowerCreator.LMS.Logic.CourseManager.ManagerCourseType courseTypeManager = new PowerCreator.LMS.Logic.CourseManager.ManagerCourseType();

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{                
            //    string groupid = Request.QueryString["GroupID"].ToString();
            //    ViewState["GroupID"] = groupid;
            //    BinderCourse();
            //    BinderCourseType();
                
            //    string search = GetSearch();
            //    BinderPager(search);
            //    BinderGV(search, 1);
            //}
        }

        /// <summary>
        /// 绑定己经管理的课程
        /// </summary>
        private void BinderCourse()
        {
            //DataTable dt = courseManager.Query(managerResourceManager.GetManagerCourseSearch(int.Parse(ViewState["GroupID"].ToString())));
            //gvCourse.DataSource = dt;
            //gvCourse.DataBind();
        }

        #region 绑定未管理的课程

        private string GetSearch()
        {
            ////成员类型,1专业，2课程
            //string search = managerResourceManager.GetNotManagerCourseSearch(int.Parse(ViewState["GroupID"].ToString()));
            //return search;
            return "";
        }
        private void BinderPager(string search)
        {
            //AspNetPager1.RecordCount = courseManager.Count(search);
            //AspNetPager1.PageSize = PowerCreator.LMS.Logic.Common.FBasePage.PageSize();
        }
        private void BinderGV(string search, int pageIndex)
        {
            //DataTable dt = new DataTable();
            //dt = courseManager.Query(search, pageIndex, PowerCreator.LMS.Logic.Common.FBasePage.PageSize());
            //gvCourse1.DataSource = dt;
            //gvCourse1.DataBind();
        }

        #endregion

        private void BinderCourseType()
        {
            //DataTable dt = new DataTable();
            //dt = courseTypeManager.Query(managerResourceManager.GetManagerCatalogSearch(int.Parse(ViewState["GroupID"].ToString())));
            //lboxCourseType.DataSource = dt;
            //lboxCourseType.DataTextField = "TypeName";
            //lboxCourseType.DataValueField = "TypeID";
            //lboxCourseType.DataBind();
        }

        protected void gvCourse_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //if (e.CommandName.ToLower() == "mydelete")
            //{
            //    string search = string.Format("SysMemberType=2 and RoleGroupID={0} and MemberID={1}", ViewState["GroupID"], e.CommandArgument.ToString());
            //    DataTable dt = managerResourceManager.Query(search, 1, 1);
            //    if (dt.Rows.Count == 1)
            //    {
            //        managerResourceManager.Delete(int.Parse(dt.Rows[0]["PKID"].ToString()));

            //        BinderCourse();
            //        search = GetSearch();
            //        BinderPager(search);
            //        BinderGV(search, 1);

            //        Script.Alert(Page, "msg", "删除成功!");
            //    }
            //    else
            //    {
            //        Script.Alert(Page, "msg", "该课程直接录属于专业下，不允许删除对该课程的管理!");
            //    }
            //}
        }
        protected void gvCourse1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //if (e.CommandName.ToLower() == "myadd")
            //{
            //    PowerCreator.LMS.Model.Entity.ManagerResource info = new PowerCreator.LMS.Model.Entity.ManagerResource();
            //    info.PKGuid = Guid.NewGuid();
            //    info.IsAccredit = 1;
            //    info.IsDeleted = 0;
            //    info.IsTop = 0;
            //    info.SysMemberType = 2;
            //    info.RoleGroupID = int.Parse(ViewState["GroupID"].ToString());
            //    info.OrderBy = 0;
            //    info.DateLastUpdate = DateTime.Now;
            //    info.DateCreated = DateTime.Now;
            //    info.MemberID = int.Parse(e.CommandArgument.ToString());

            //    bool bl = managerResourceManager.AddNew(info);
            //    if (bl)
            //    {
            //        BinderCourse();
            //        string search = GetSearch();
            //        BinderPager(search);
            //        BinderGV(search, 1);
            //        Script.Alert(Page, "msg", "添加成功!");
            //    }
            //    else
            //    {
            //        Script.Alert(Page, "msg", "添加失败!");
            //    }
            //}
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            //string url = "ActionManage.aspx";
            //Script.RedirectURL(url);
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            //string search = GetSearch();
            //BinderGV(search, AspNetPager1.CurrentPageIndex);
        }
    }
}